/**
 * Created by Auser on 2016/12/2.
 */

function generate_preview(lines,strHtml){
    var LODOP = getLodop();
    //1.初始化
    LODOP.PRINT_INIT("打印任务名");
    //2.设定大小
    //2.1 计算尺寸，根据itemNum来计算
    var item_height = 100; //一行的高度
    var page_height = 1500; //打印纸初始化高度
    var page_width = 800;	//打印纸宽度
    page_height += item_height * lines;
    LODOP.SET_PRINT_PAGESIZE(1,page_width,page_height,"");
    //3.添加数据
    //var strHtml = "<table style='font-size:14px;'>";
    //strHtml += "<tr><td style='font-size:20px;'>微歌互联网KTV--长沙旗舰店</td></tr>";  //一行数据
    //strHtml += "<tr style='height:18px;'><td ></td></tr>";  //一行数据
    //strHtml += "<tr><td>订单号：11111011010101</td></tr>";  //一行数据
    //strHtml += "<tr><td>订单时间：2016-10-11 12:11:11</td></tr>";  //一行数据
    //strHtml += "<tr><td>手机号：13120300000</td></tr>";  //一行数据
    //strHtml += "<tr><td>房间号：101</td></tr>";  //一行数据
    //
    //strHtml += "<tr style='height:18px;'><td></td></tr>";  //一行数据
    //strHtml += "<tr style='font-size:18px;'><td>清单：</td><td></td></tr>";  //一行数据
    //strHtml += "<tr ><td><hr/></td></tr>";  //一行数据
    ////strHtml += "</table>";
    ////strHtml += "<table style='border:1px ;'>";
    ////strHtml += "<tr><td>名称</td><td>数量</td><td>金额</td></tr>";
    ////strHtml += "<tr><td>名称1</td><td>2</td><td>110.00元</td></tr>";
    ////strHtml += "<tr><td>名称2</td><td>3</td><td>200.00元</td></tr>";
    ////strHtml += "<tr><td>名称3</td><td>3</td><td>200.00元</td></tr>";
    //strHtml += "<tr><td cols='2'>商品名1&nbsp;&nbsp;&nbsp;&nbsp;x3&nbsp;&nbsp;&nbsp;&nbsp;100.00元</td></tr>";  //一行数据
    //strHtml += "<tr><td cols='2'>商品名1&nbsp;&nbsp;&nbsp;&nbsp;x3&nbsp;&nbsp;&nbsp;&nbsp;100.00元</td></tr>";  //一行数据
    //strHtml += "<tr><td cols='2'>商品名1&nbsp;&nbsp;&nbsp;&nbsp;x3&nbsp;&nbsp;&nbsp;&nbsp;100.00元</td></tr>";  //一行数据
    //
    //strHtml += "<tr ><td><hr/></td></tr>";  //一行数据
    //strHtml += "<tr ><td>总计：8888.00元</td></tr>";  //一行数据
    //strHtml += "</table>";
    LODOP.ADD_PRINT_HTM(80,40,page_width,page_height,strHtml); // 离顶部距离，离左边距离，页面宽度，页面高度，HTML内容
    //4.打印预览
    LODOP.PREVIEW();
}

function generate_commodity_html(oc){

    var strHtml = "<table style='font-size:12px;'>";
    strHtml += "<tr style='width:740px;'><td style='font-size:20px;'>"+oc.shopName+"</td></tr>";  //一行数据
    strHtml += "<tr style='height:18px;'><td ></td></tr>";  //一行数据
    strHtml += "<tr><td>订单号："+oc.orderNo+"</td></tr>";  //一行数据
    strHtml += "<tr><td>订单时间："+datetime_pattern(oc.orderTime)+"</td></tr>";  //一行数据
    strHtml += "<tr><td>打印时间："+datetime_pattern(new Date().getTime())+"</td></tr>";  //一行数据
    strHtml += "<tr><td>手机号："+oc.userPhone+"</td></tr>";  //一行数据

    switch(oc.orderStatus){
        case -2:
            strHtml += "<tr><td>订单状态：已退款</td></tr>";  //一行数据
            break;
        case -1:
            strHtml += "<tr><td>订单状态：已取消</td></tr>";  //一行数据
            break;
        case 0:
            strHtml += "<tr><td>订单状态：未支付</td></tr>";  //一行数据
            break;
        case 1:
            strHtml += "<tr><td>订单状态：已付款</td></tr>";  //一行数据
            break;
        case 2:
            strHtml += "<tr><td>订单状态：备货中</td></tr>";  //一行数据
            break;
        case 3:
            if(oc.orderType == 1){ //现场购
                strHtml += "<tr><td>订单状态：配送中</td></tr>";  //一行数据
            }else if(oc.orderType == 2){ //预定购
                strHtml += "<tr><td>订单状态：已核销</td></tr>";  //一行数据
            }else{
                strHtml += "<tr><td>订单状态：-</td></tr>";  //一行数据
            }
            break;
        case 4:
            if(oc.orderType == 1){ //现场购
                strHtml += "<tr><td>订单状态：完成</td></tr>";  //一行数据
            }else if(oc.orderType == 2){ //预定购
                strHtml += "<tr><td>订单状态：配送中</td></tr>";  //一行数据
            }else{
                strHtml += "<tr><td>订单状态：-</td></tr>";  //一行数据
            }
            break;
        case 5:
            strHtml += "<tr><td>订单状态：完成</td></tr>";  //一行数据
            break;
    }

    if(oc.orderType == 1){
        strHtml += "<tr><td>订单类型：现场购</td></tr>";  //一行数据
    }else if(oc.orderType == 2){
        strHtml += "<tr><td>订单类型：预定购</td></tr>";  //一行数据
    }else{
        strHtml += "<tr><td>订单类型：-</td></tr>";  //一行数据
    }
    if(null != oc.roomName && oc.orderType == 1){
        strHtml += "<tr><td>房间号："+oc.roomName+"</td></tr>";  //一行数据
    }

    switch(oc.payType){
        case 1:
            strHtml += "<tr><td>支付类型：微信支付</td></tr>";  //一行数据
            break;
        case 2:
            strHtml += "<tr><td>支付类型：账号支付</td></tr>";  //一行数据
            break;
        default :
            strHtml += "<tr><td>支付类型：-</td></tr>";  //一行数据
            break;
    }

    if(null != oc.remark){
        strHtml += "<tr><td>备注："+oc.remark+"</td></tr>";
    }else{
        strHtml += "<tr><td>备注：-</td></tr>";
    }

    strHtml += "<tr style='height:18px;'><td></td></tr>";  //一行数据
    strHtml += "<tr style='font-size:18px;'><td>清单：</td></tr>";  //一行数据
    strHtml += "<tr ><td><hr/></td></tr>";  //一行数据
    //strHtml += "</table>";
    //strHtml += "<table style='border:1px ;'>";
    //strHtml += "<tr><td>名称</td><td>数量</td><td>金额</td></tr>";
    //strHtml += "<tr><td>名称1</td><td>2</td><td>110.00元</td></tr>";
    //strHtml += "<tr><td>名称2</td><td>3</td><td>200.00元</td></tr>";
    //strHtml += "<tr><td>名称3</td><td>3</td><td>200.00元</td></tr>";
    var ocds = oc.orderCommodityDetails;
    var item_num = ocds.length;
    for(i=0;i<item_num;i++){
        var item = ocds[i];
        if(item.orderStatus == -1){ //已退款
            strHtml += "<tr><td style='TEXT-DECORATION: line-through'>"+item.commodityName+"&nbsp;&nbsp;&nbsp;&nbsp;x "+item.commodityTotalAmount+"&nbsp;&nbsp;&nbsp;&nbsp;"+item.commodityTotalPrice+"元</td></tr>";  //一行数据
        }else{
            strHtml += "<tr><td>"+item.commodityName+"&nbsp;&nbsp;&nbsp;&nbsp;x "+item.commodityTotalAmount+"&nbsp;&nbsp;&nbsp;&nbsp;"+item.commodityTotalPrice+"元</td></tr>";  //一行数据
        }
    }
    strHtml += "<tr ><td><hr/></td></tr>";  //一行数据
    var secondPrice = oc.orderSecondPrice;
    if(null == secondPrice && 0 != secondPrice){
        if(oc.orderStatus >= 1) {
            strHtml += "<tr ><td>总计：" + oc.payAmount + "元</td></tr>";  //一行数据
        }else{
            strHtml += "<tr ><td>总计：" + oc.orderPrice + "元</td></tr>";  //一行数据
        }
    }else{
        strHtml += "<tr ><td>总计："+secondPrice+"元（原订单总金额："+oc.payAmount+"元）</td></tr>";  //一行数据
    }
    strHtml += "</table>";
    return strHtml;
}
